package el;

import com.greenpineyu.fel.FelEngine;
import com.greenpineyu.fel.FelEngineImpl;
import com.greenpineyu.fel.context.FelContext;
import org.apache.commons.lang3.ObjectUtils;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

public class test {
    public static Object result(Map<String, Object> map, String expression) {
        FelEngine fel = new FelEngineImpl();
        FelContext ctx = fel.getContext();
        for (Map.Entry<String, Object> entry : map.entrySet()) {
            ctx.set(entry.getKey(), entry.getValue());
        }
        Object result = fel.eval(expression);
        return result;
    }


//    ${ isMaximumRufs == 'y' && lmtAmt >= '100' && ( (croptotal >= '500'  && loanType == 'dg') || (croptotal >= '300'  && loanType == 'gr')  )}
//
//    ${ isMaximumRufs == 'y' && lmtAmt < '100' && ( (croptotal >= '500'  && loanType == 'dg') || (croptotal >= '300'  && loanType == 'gr')  )}
//
    public static void main(String[] args) {
        HashMap<String, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("isMaximumRufs","y");
        objectObjectHashMap.put("lmtAmt","90");
        objectObjectHashMap.put("croptotal","700");
        String s = "1";
        System.out.println(s.toString());
        //方式一
        BigDecimal bigDecimal = new BigDecimal(s);
        objectObjectHashMap.put("lmtAmt",bigDecimal);
        objectObjectHashMap.put("loanMajorType","gr");
            objectObjectHashMap.put("lmtAmt",new BigDecimal(objectObjectHashMap.get("lmtAmt").toString())) ;
            objectObjectHashMap.put("croptotal",new BigDecimal(objectObjectHashMap.get("croptotal").toString())) ;
//        Object result = result(objectObjectHashMap, "isMaximumRufs == 'y' && lmtAmt < '100' && ( (croptotal >= '500'  && loanType == 'dg') || (croptotal >= '300'  && loanType == 'gr')  )");
        Object result = result(objectObjectHashMap, " (croptotal >= 500  && loanMajorType== 'dg' && lmtAmt < 500 && isMaximumRufs == 'y' ) || (croptotal >= 300  && loanMajorType== 'gr' && lmtAmt < 300 && isMaximumRufs == 'y' )  ");
        System.out.println(result);
    }
}
